/*
 * TOP SECRET Copyright 2006-2015 Transsion.com All right reserved. This software is the confidential and proprietary
 * information of Transsion.com ("Confidential Information"). You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement you entered into with Transsion.com.
 */
package com.yunji.framework_template.biz.crawler.ke;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yunji.framework_template.biz.crawler.ContentImageHandler;
import com.yunji.framework_template.biz.crawler.NewsCrawler;
import com.yunji.framework_template.biz.crawler.SourceType;
import com.yunji.framework_template.common.enumeration.CountryCode;
import com.yunji.framework_template.common.enumeration.NewsType;

/**
 * ClassName:NationNewsCrawler <br/>
 * Date: 2018年12月18日 下午3:31:24 <br/>
 * 
 * @author fenglibin1982@163.com
 * @Blog http://blog.csdn.net/fenglibing
 * @version
 * @see
 */
@Service
public class TheStarsNewsCrawler extends NewsCrawler {

	@Resource
	private TheStarsNewsImageHandler theStarsNewsImageHandler;

	@Override
	public boolean isOkUrl(String url) {
		// 新闻详情url格式如：https://citizentv.co.ke/news/10yr-old-girl-found-hanging-from-a-rope-in-rarieda-223708/
		// 通过判断url的path中是否包括年月来判断其是否为新闻详情页
		URI uri;
		try {
			if (url == null || url.trim().length() == 0) {
				return false;
			}
			if (url.startsWith("mailto") || url.toLowerCase().startsWith("javascript")) {
				return false;
			}
			uri = new URI(url);
			String host = uri.getHost();
			if(host==null) {
                return false;
            }
			if (host.indexOf("the-star.co.ke") < 0 && host.indexOf("the-starvideos.co.ke") < 0) {
				return false;
			}
			String path = uri.getPath();
			String[] pathArr = path.split("/");
			if (pathArr.length == 6) {
				return true;
			}
		} catch (URISyntaxException e) {
		}
		return false;
	}

	@Override
	public ContentImageHandler getContentImageHandler() {
		return theStarsNewsImageHandler;
	}

	@Override
	public List<SourceType> getSourceTypeList() {
		List<SourceType> sourceTypeList = new ArrayList<SourceType>();
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/").newsType(NewsType.HOT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/latest-news_c401249").newsType(NewsType.EDUCATION).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/latest-news/devolved-corruption_c401482").newsType(NewsType.VIDEO).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/latest-news/pictorial_c401415").newsType(NewsType.IMAGE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/latest-news/the-conversation_c401480").newsType(NewsType.SPORT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/latest-news/world_c401405").newsType(NewsType.LIFESTYLE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/national-news_c29654").newsType(NewsType.FUN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/national-news/corridors-of-power_c401194").newsType(NewsType.HOUSE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/taxonomy/term/118/").newsType(NewsType.ASKANDANSWER).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/national-news/big-read_c401420").newsType(NewsType.HEALTH).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news_c29655").newsType(NewsType.MILITARY).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news/central_c29659").newsType(NewsType.CAR).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news/coast_c29656").newsType(NewsType.TECH).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news/nairobi_c401426").newsType(NewsType.FINANCE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news/north-eastern_c29660").newsType(NewsType.NEWS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news/nyanza_c401402").newsType(NewsType.BUSINESS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news/rift-valley_c29657").newsType(NewsType.ENTERTAINMENT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/local-news/western_c29658").newsType(NewsType.BLOG).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business_c29663").newsType(NewsType.MAN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/commentary_c66839").newsType(NewsType.WOMAN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/aly-khan_c65834").newsType(NewsType.KIDS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/andrea-bohnstedt_c401206").newsType(NewsType.FOOD).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/marketing-medicine_c401246").newsType(NewsType.POLITICS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/james-mbugua_c401374").newsType(NewsType.HOT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/karen-kandie_c401392").newsType(NewsType.EDUCATION).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/news/business/features_c66840").newsType(NewsType.VIDEO).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/property_c401158").newsType(NewsType.IMAGE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sport_c29664").newsType(NewsType.SPORT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sport/chess-in-black-white_c401385").newsType(NewsType.LIFESTYLE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sport/gun-point_c401212").newsType(NewsType.FUN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sport/radull-predicts_c401213").newsType(NewsType.HOUSE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion_c29661").newsType(NewsType.ASKANDANSWER).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/dr-alex-awiti_c401244").newsType(NewsType.HEALTH).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/gwynne-dyer_c401180").newsType(NewsType.MILITARY).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/hassan-ole-naado_c401234").newsType(NewsType.CAR).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/john-githongo_c401422").newsType(NewsType.TECH).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/koigi-wamwere_c401377").newsType(NewsType.FINANCE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/miguna-miguna_c401190").newsType(NewsType.NEWS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/moses-kuria_c401182").newsType(NewsType.BUSINESS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/ngunjiri-wambugu_c401226").newsType(NewsType.ENTERTAINMENT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/njonjo-kihuria_c401416").newsType(NewsType.BLOG).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/okech-kendo_c401378").newsType(NewsType.MAN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/patrick-gathara_c401399").newsType(NewsType.WOMAN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/project-syndicate_c401250").newsType(NewsType.KIDS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/wycliffe-muga_c401185").newsType(NewsType.FOOD).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/opinion/prof-yash-ghai_c401192").newsType(NewsType.POLITICS).build());
		sourceTypeList.add(SourceType.builder().url("http://health.the-star.co.ke/").newsType(NewsType.HOT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/latest-news/off-beat_c401413").newsType(NewsType.EDUCATION).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle_c29662").newsType(NewsType.VIDEO).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/5-min-interview_c401204").newsType(NewsType.SPORT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/ask-valentine_c401200").newsType(NewsType.LIFESTYLE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/diary-of-a-mum_c401197").newsType(NewsType.FUN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/family-law_c401196").newsType(NewsType.HOUSE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/medics-view_c401195").newsType(NewsType.ASKANDANSWER).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/mutoko-on-monday_c401202").newsType(NewsType.HEALTH).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/parenting_c401198").newsType(NewsType.MILITARY).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/the-extreme-side_c401201").newsType(NewsType.CAR).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/fashion_c401417").newsType(NewsType.TECH).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/business/features_c66840").newsType(NewsType.FINANCE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/agriculture_c401396").newsType(NewsType.NEWS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/education_c401398").newsType(NewsType.BUSINESS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/science-and-environment_c401397").newsType(NewsType.ENTERTAINMENT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/star-tech_c401231").newsType(NewsType.BLOG).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/society_c29665").newsType(NewsType.MAN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/asian-scene_c401203").newsType(NewsType.WOMAN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/just-bollywood_c401199").newsType(NewsType.KIDS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/lifestyle/word-is_c29666").newsType(NewsType.FOOD).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa_c147383").newsType(NewsType.POLITICS).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa_c147383").newsType(NewsType.HOT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa/bushman-adventures_c401210").newsType(NewsType.EDUCATION).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa/g-spot_c401208").newsType(NewsType.VIDEO).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa/love-matters_c401376").newsType(NewsType.IMAGE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa/nairobi-living_c401211").newsType(NewsType.SPORT).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa/samantha-chronicles_c401411").newsType(NewsType.LIFESTYLE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/sasa/the-last-round_c401209").newsType(NewsType.FUN).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/siasa_c147384").newsType(NewsType.HOUSE).build());
		sourceTypeList.add(SourceType.builder().url("https://www.the-star.co.ke/sections/siasa/katiba-corner_c401404").newsType(NewsType.ASKANDANSWER).build());

		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/").newsType(NewsType.HOT).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/news/").newsType(NewsType.EDUCATION).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/politics/").newsType(NewsType.VIDEO).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/analysis/").newsType(NewsType.IMAGE).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/business/").newsType(NewsType.SPORT).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/sports/").newsType(NewsType.LIFESTYLE).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/lifestyle/").newsType(NewsType.FUN).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/features/").newsType(NewsType.HOUSE).build());
		sourceTypeList.add(SourceType.builder().url("http://the-starvideos.co.ke/index.php/category/entertainment/").newsType(NewsType.ASKANDANSWER).build());
		return sourceTypeList;
	}

	@Override
    public Set<String> getCountryCodeSet() {
        Set<String> countryCodeSet = new HashSet<String>();
        countryCodeSet.add(CountryCode.KE.name());
        return countryCodeSet;
    }
}
